package com.sunjq;

public class Reverse {

	private String content;
	private Reverse next;

	public Reverse() {

	}

	public Reverse(String s) {
		this.content = s;
	}

	public Reverse(String s, Reverse r) {
		this.content = s;
		this.next = r;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Reverse getNext() {
		return next;
	}

	public void setNext(Reverse next) {
		this.next = next;
	}

	public static void main(String[] args) {

		Reverse end = new Reverse("end");
		Reverse r6 = new Reverse("6", end);
		Reverse r5 = new Reverse("5", r6);
		Reverse r4 = new Reverse("4", r5);
		Reverse r3 = new Reverse("3", r4);
		Reverse r2 = new Reverse("2", r3);
		Reverse r1 = new Reverse("1", r2);
		Reverse start = new Reverse("start", r1);

		System.out.println("before reverse");

		System.out.print(start.getContent() + ", " + start.getNext().getContent()
				+ ", " + start.getNext().getNext().getContent() + ", " );

		System.out.print(start.getNext().getNext().getNext().getContent() 
				+ ", " + start.getNext().getNext().getNext().getNext().getContent()+ ", " );
		
		System.out.print(start.getNext().getNext().getNext().getNext().getNext().getContent() 
				+ ", " + start.getNext().getNext().getNext().getNext().getNext().getNext().getContent()+ ", " );
		System.out.print(start.getNext().getNext().getNext().getNext().getNext().getNext().getNext().getContent());
		System.out.println();

		System.out.println("after reverse");
		
		Reverse pre = start;
		Reverse cur = start.getNext();
		
		while (null != cur.getNext() ) {
			Reverse temp1 = cur.getNext();
			cur.setNext(pre);
			pre=cur;
			cur = temp1;
		}
		cur.setNext(pre);
		start = cur;
		System.out.println("cur =>" + cur.getContent());
		System.out.println("pre =>" + pre.getContent());
		System.out.println("start =>" + start.getContent());
		System.out.println("end =>" + end.getContent());
		
		
		
		System.out.print(start.getContent() + ", " + start.getNext().getContent()
				+ ", " + start.getNext().getNext().getContent() + ", " );

		System.out.print(start.getNext().getNext().getNext().getContent() 
				+ ", " + start.getNext().getNext().getNext().getNext().getContent());
		System.out.println();

	}
}
